#include <iostream>
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include <memory>
#include "../mqserver/route.hpp"
using namespace std;

class RouterTest : public testing::Environment {
public :
    virtual void SetUp() override {

    }
    virtual void TearDown() override {

    }
private :
};

// TEST(router_test, legal_routing_key) {
//     string routing_key1 = "news.music.pop";
//     string routing_key2 = "news...music.pop";
//     string routing_key3 = "news.,mus_ic.pop";
//     string routing_key4 = "news.mAusic.123pop";
//     ASSERT_EQ(rbmq::Router::routingKeyIsLegal(routing_key1), true);
//     ASSERT_EQ(rbmq::Router::routingKeyIsLegal(routing_key2), true);
//     ASSERT_EQ(rbmq::Router::routingKeyIsLegal(routing_key3), false);
//     ASSERT_EQ(rbmq::Router::routingKeyIsLegal(routing_key4), true);
// }

// TEST(router_test, rout_binding_key) {
//     string binding_key1 = "news.music.pop";
//     string binding_key2 = "news.#.music.*.pop";
//     string binding_key3 = "news.#.#.mus_ic.pop";
//     string binding_key4 = "news.,mAusic.123pop";
//     string binding_key5 = "news.*.*.mAusic.123pop";
//     string binding_key6 = "news.mu#sic.pop";
//     ASSERT_EQ(rbmq::Router::bindingKeyIsLegal(binding_key1), true);
//     ASSERT_EQ(rbmq::Router::bindingKeyIsLegal(binding_key2), true);
//     ASSERT_EQ(rbmq::Router::bindingKeyIsLegal(binding_key3), false);
//     ASSERT_EQ(rbmq::Router::bindingKeyIsLegal(binding_key4), false);
//     ASSERT_EQ(rbmq::Router::bindingKeyIsLegal(binding_key5), true);
//     ASSERT_EQ(rbmq::Router::bindingKeyIsLegal(binding_key6), false);
// }

TEST(router_test, rout_test) {
    mqNs::ExchangeType type = mqNs::ExchangeType::TOPIC;
    ASSERT_EQ(rbmq::Router::route(type, "aaa", "aaa"), true);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.bbb", "aaa.bbb"), true);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.bbb", "aaa.bbb.ccc"), false);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.bbb", "aaa.ccc"), false);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.#.bbb", "aaa.bbb.ccc"), false);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.bbb.#", "aaa.ccc.bbb"), false);
    ASSERT_EQ(rbmq::Router::route(type, "#.bbb.ccc", "aaa.bbb.ccc.ddd"), false);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.*", "aaa.bbb"), true);
    ASSERT_EQ(rbmq::Router::route(type, "#", "aaa.bbb.ccc"), true);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.#", "aaa.bbb"), true);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.#", "aaa.bbb.ccc"), true);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.#.ccc", "aaa.ccc"), true);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.#.ccc", "aaa.bbb.ccc"), true);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.#.ccc", "aaa.aaa.bbb.ccc"), true);
    ASSERT_EQ(rbmq::Router::route(type, "#.ccc", "ccc"), true);
    ASSERT_EQ(rbmq::Router::route(type, "#.ccc", "aaa.bbb.ccc"), true);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.#.ccc.ccc", "aaa.bbb.ccc.ccc.ccc"), true);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.#.bbb.*.bbb", "aaa.ddd.ccc.bbb.eee.bbb"), true);
    ASSERT_EQ(rbmq::Router::route(type, "*.aaa.bbb", "aaa.bbb"), false);
    ASSERT_EQ(rbmq::Router::route(type, "aaa.*.bbb", "aaa.bbb.ccc"), false);
    // ASSERT_EQ(rbmq::Router::route(type, "", ""), true);

    

}




int main(int argc, char* args[]) {
    testing::InitGoogleTest(&argc, args);
    // testing::AddGlobalTestEnvironment(new HostTest());
    RUN_ALL_TESTS();
    return 0;
}
